# -*- coding:utf-8 -*-
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import HttpResponse
from compsite.webutils.forms import PicturesIniForm,InstituctionalDockForm
from compsite.webutils.imageUploadHandlers import picturesIniUploadHandler,InstituctionalDockUploadHandler

def picturesIniUpload(request):
    if request.method=="POST":
        form=PicturesIniForm(request.POST,request.FILES)
        if form.is_valid():
            alt=form.cleaned_data['alt']
            pictureIni=picturesIniUploadHandler(request.FILES['imagem'],alt)#upload e resize
            pictureIni.alt=alt
            pictureIni.save()
            form=PicturesIniForm()
    else:
        form=PicturesIniForm()
    return render_to_response("form.html",\
                              {"form":form},\
                              context_instance=RequestContext(request))


def instituctionalDockUpload(request):
    if request.method=="POST":
        form=InstituctionalDockForm(request.POST,request.FILES)
        if form.is_valid():
            alt=form.cleaned_data['nomeInstituicao']
            instituctionalDock=InstituctionalDockUploadHandler(request.FILES['imagem'],alt)#upload e resize
            instituctionalDock.alt=alt
            instituctionalDock.save()
            form=InstituctionalDockForm()
    else:
        form=InstituctionalDockForm()
    return render_to_response("form.html",\
                              {"form":form},\
                              context_instance=RequestContext(request))
